import React, { useContext, useMemo, useState } from 'react';
import { checkerSource } from '@@/hw-auth/fns/authProvider';
import { sourceData } from '@@/hw-auth/sourceData';
import { RouteModal } from '@@/hw-auth/modal.d';

const SettingAuthContext = React.createContext({});

interface AuthModal {
  appKeyList: string[];
  authData: string | null;
  type: number;
}

export const HwSettingAuthRoot: React.FC = ({ children }) => {
  const [change, setChange] = useState<boolean>(true);
  const settingAuthChecker = useMemo(() => {
    const checker = checkerSource();
    checker.set({
      type: 1,
    });
    return checker;
  }, []);
  const initAuth = (data: AuthModal) => {
    settingAuthChecker.up(data);
    setChange(!change);
  };
  return (
    <SettingAuthContext.Provider
      value={{
        initAuth,
        settingAuthChecker,
      }}
    >
      {children}
    </SettingAuthContext.Provider>
  );
};
export const useHwSettingAuthControl = () => {
  return useContext(SettingAuthContext);
};
